//
//  RCNetSocketRequest.h
//  RCNetRequestProject
//
//  Created by kabu on 2017/8/14.
//  Copyright © 2017年 RC. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "RCSocketSendSerializationer.h"
#import "RCSocketAcceptSerializationer.h"
/**
 服务器数据返回时的回调

 @param result 回调结果
 @param error 错误
 */
typedef void (^RCServerSocketCallBack)(id result,NSError *error);

/**
 链接Socket状态回调

 @param result 结果
 @param error 错误
 */
typedef void (^RCConnectSocketCallBack)(id result,NSError *error);
@protocol RCNetSocket <NSObject>

/**
 根据iP地址访问某个端口的Socket

 @param ip ip地址
 @param aPort 端口号
 @param aCallBack 链接状态反馈
 */
- (void) connectIP:(NSString*)ip port:(int)aPort callBack:(RCConnectSocketCallBack)aCallBack;

/**
 写入Socket数据

 @param message 数据
 @return 写入状态 大于0：成功 小于等于0：失败
 */
- (NSInteger) write:(id)message;

/**
 读取Socket数据

 @param buf 承载读取数据的内存
 @return 读取的数据
 */
- (NSData*) read:(uint8_t)buf;
- (void) disconnect;
@end
@interface RCNetSocketRequest : NSObject <RCNetSocket>
@property (nonatomic, readwrite, strong) NSString *host;
@property (nonatomic, readwrite, assign) int port;
@property (nonatomic, readonly,strong) id<RCSocketSendSerialization> senderSerializationer;
@property (nonatomic, readonly,strong) id<RCSocketAcceptSerialization> acceptSerializationer;
-(instancetype)initWithSendSerializationer:(id<RCSocketSendSerialization>)aSendSerializationer acceptSerializationer:(id<RCSocketAcceptSerialization>)aAcceptSerializationer;

/**
 设置请求和处理的配置器

 @param aSendSerializationer 发送的配置器
 @param aAcceptSerializationer 接受的配置器
 */
-(void)setSender:(id<RCSocketSendSerialization>)aSendSerializationer accepter:(id<RCSocketAcceptSerialization>)aAcceptSerializationer;
/**
 获取单例

 @return 对象
 */
+(instancetype)sharedInstance;

/**
 服务器返回数据的回调

 @param aCallback 回调
 */
-(void)setRCServerSocketCallBack:(RCServerSocketCallBack)aCallback;
@end
